const express = require('express');
const app = express();
const fs = require('fs');
const path = require('path');
const cors = require('cors');

app.use(cors());

app.use(express.static('./public'));


app.get('/getImgList', async (req, res) => {
    let result = await getImgSrc();
    res.send(result);
});


function getImgSrc(){
    return new Promise((resolve, reject) => {
        fs.readdir(path.resolve('./public/images'), (err, result) => {
            if(err){
                return reject(err);
            }
            result = result.map(item => '/images/' + item);
            resolve(result);
        });
    });
}


app.listen(9090, () => {
    console.log(`server is running at 9090 ...`);
});

